<?php

namespace km\util;

use \SplObjectStorage;

class InterceptingFilterChain {
	/**
	 * @var SplObjectStorage
	 */
	private $filters;
	
	function __construct()
	{
		$this->filters = new SplObjectStorage();
	}
	
	function add(InterceptingFilter $f)
	{
		$this->filters->attach($f);
	}
	
	function run()
	{
		$this->filters->rewind();
		return $this->next();
	}
	/**
	 * @return void
	 */
	function next()
	{
		if ($this->filters->valid()) {
			$filter = $this->filters->current();
			$this->filters->next();
			return $filter->filter($this);
		}
	}
}